﻿namespace Vkontakte.Api.Operations
{
	[ApiMethod("photos.getAlbums")]
	public sealed class PhotosGetAlbums
		: Base30ApiOperation
	{
		private PhotoAlbum[] _albums;
		public PhotosGetAlbums()
		{

		}

		protected override void Compile()
		{
			AddParameter("method", "photos.getAlbums");
			if (UserUID != null)
			{
				AddParameter("uid", UserUID.Value.ToString());
			}

			base.Compile();
		}

		protected override void ParseData(string data)
		{
			ListingResponce responce = Serializer.LoadObjectXmlString<ListingResponce>(data);
			_albums = responce.PhotoAlbums;
			for (int i = 0; i < _albums.Length;i++ )
			{
				_albums[i].Description = _albums[i].Description.FixXmlString();
			}
			base.ParseData(data);
		}

		public long? UserUID { get; set; }

		public PhotoAlbum[] GetResult()
		{
			return _albums;
		}
	}
}